package com.kitty.game.utils;


/**
 * 计算公式
 */
public class FormulaUtil {

    /**
     * 获取等级标准道行 天数
     *
     * @param level
     * @return
     */
    public static double getStdTao(int level) {
        return Math.pow(level, 3) * 0.29;
    }

    /**
     * 获取等级标准武学 天数
     *
     * @param level
     * @return
     */
    public static int getStdMartial(int level) {
        double value = Math.pow(level, 3) * 0.29 * 2;
        return (int) Math.ceil(value);
    }


    /**
     * 获取标准攻击
     *
     * @param level
     * @return
     */
    public static double getStdAttack(int level) {
        level = level - 1;
        return Math.floor(level * level * 1.39 + 85 * level + 100) * 4 / 10;
    }

    /**
     * 获取标准防御
     *
     * @param level
     * @return
     */
    public static double getStdDefense(int level) {
        level = level - 1;
        return Math.floor(1.39 * level * level + 85 * level + 100) / 15;
    }

    /**
     * 获取标准气血
     *
     * @param level
     * @return
     */
    public static double getStdLife(int level) {
        level = level - 1;
        return Math.floor(1.39 * level * level + 85 * level + 100);
    }

    /**
     * 获取标准法力
     *
     * @param level
     * @return
     */
    public static double getStdMana(int level) {
        level = level - 1;
        return Math.floor(0.93 * level * level + 56 * level + 80);
    }

    /**
     * 获取标准速度
     *
     * @param level
     * @return
     */
    public static double getStdSpeed(int level) {
        level = level - 1;
        return Math.floor(level * 6 + 50);
    }


    /**
     * 获取属性点洗点费用？
     *
     * @param level
     * @return
     */
    public static double getAttribCost(int level, int point) {
        if (point <= 0) {
            return 0;
        }
        return Math.max(1, Math.floor(Math.max(0.1, (1.0 - 0.0005 * point) * Math.min(1.0, Math.pow(1.0 * level / 120, 2))) * point * 108));
    }

    /**
     * 获得洗相性点费用
     */
    public static double getPolarCost(int point) {
        return 164 * point;
    }


    /**
     * 获取宠物物理攻击
     *
     * @param str
     * @param phyShape
     * @param petLevel
     * @return
     */
    public static double getPetPhyPower(int str, int phyShape, int petLevel) {
        int phyEffect = phyShape - 40;
        double levelFactor = Math.floor(petLevel / 4);

        if (levelFactor > 30) {
            levelFactor = 30;
        }

        double rawValue = Math.floor((str * levelFactor * 5 * 4 / 42 + str * 5) * 2 * (1 + phyEffect / 100) + 100);
        double phyFactor = 0.63 + 0.01 * (petLevel - 1);

        if (phyFactor > 1) {
            phyFactor = 1;
        }
        return Math.floor(rawValue * phyFactor);
    }

    /**
     * 获取宠物法术攻击
     *
     * @param wiz
     * @param magShape
     * @param petLevel
     * @return
     */
    public static double getPetMagPower(int wiz, int magShape, int petLevel) {
        int magEffect = magShape - 40;
        double levelFactor = Math.floor(petLevel / 4);

        if (levelFactor > 30) {
            levelFactor = 30;
        }
        return Math.floor(1.3 * (wiz * levelFactor * 5 * 4 / 42 + wiz * 5) * 2 * (1 + magEffect / 100) + 100);
    }


    /**
     * 当前等级法宝的最大灵气
     */

    public static int getArtifactMaxNimbus(int level) {
        return (100 * level * level + 300) * 5;
    }

    /**
     * 取法宝补灵气需要多少金钱
     */
    public static int getRefillArtifactNimbusNeedCash(int currNimbus, int level) {
        return (getArtifactMaxNimbus(level) - currNimbus) * 100;
    }


    /**
     * 单次物攻强化成长值
     */
    public static int getPhyRebuildDelta(int std_value, int rebuild_add) {
        double delta = Math.max(Math.floor((std_value + 50) * 0.08), 1.0);
        if (std_value + 50 + rebuild_add + delta > 165) {
            delta = Math.floor(Math.max(0.0, 165 - (std_value + 50 + rebuild_add)));
        }
        return (int) delta;
    }

    /**
     * 单次法攻强化成长值
     */
    public static int getMagRebuildDelta(int std_value, int rebuild_add) {
        double delta = Math.max(Math.floor((std_value + 50) * 0.08), 1.0);
        if (std_value + 50 + rebuild_add + delta > 135) {
            delta = Math.max(0.0, 135 - (std_value + 50 + rebuild_add));
        }
        return (int) delta;
    }


    /**
     * 装备取值取整数
     */
    public static int getIntValue(double score, String field) {
        if (field.equals("power") || field.equals("def") || field.equals("max_life") || field.equals("max_mana") || field.equals("speed")) {
            if (score >= 10000) {
                return (int) (Math.floor(score / 1000) * 1000);
            } else if (score >= 5000) {
                if (field.equals("power")) {
                    return (int) (Math.floor(score / 200) * 200);
                }
                return (int) (Math.floor(score / 500) * 500);
            } else if (score >= 2000) {
                return (int) (Math.floor(score / 200) * 200);
            } else if (score >= 1000) {
                return (int) (Math.floor(score / 100) * 100);
            } else if (score >= 500) {
                return (int) (Math.floor(score / 50) * 50);
            } else if (score >= 200) {
                return (int) (Math.floor(score / 20) * 20);
            } else if (score >= 100) {
                return (int) (Math.floor(score / 10) * 10);
            } else if (score >= 30) {
                return (int) (Math.floor(score / 5) * 5);
            } else {
                return (int) score;
            }
        } else {
            return (int) score;
        }
    }
    /**
     * 取属性的最小值
     */
    public static int getAttribMinValueByName(int equipLevel, int pos, String name) {
        switch (name) {
            case "power":
                return getIntValue(Math.floor(getStdLife(equipLevel) * 0.4 * 0.4 * 0.05), name);
            case "def": {
                double maxPercent = 0;
                if (equipLevel >= 100) {
                    maxPercent = 0.3;
                } else {
                    maxPercent = 0.25;
                }
                if (pos == Const.ARMOR) {
                    return getIntValue(Math.floor(getStdLife(equipLevel) / 15 * 0.5 * maxPercent), name);
                } else {
                    return getIntValue(Math.floor(getStdLife(equipLevel) / 15 * 0.25 * maxPercent), name);
                }
            }
            case "max_life": {
                double maxPercent = 0;// 最大值系数

                if (equipLevel >= 100) {
                    maxPercent = 0.3;
                } else {
                    maxPercent = 0.25;
                }
                if (pos == Const.ARMOR) {
                    return getIntValue(Math.floor(getStdLife(equipLevel) * 0.105 * maxPercent), name);
                } else {
                    return getIntValue(Math.floor(getStdLife(equipLevel) * 0.06 * maxPercent), name);
                }
            }
            case "max_mana": {
                double maxPercent = 0;//最大值系数

                if (equipLevel >= 100) {
                    maxPercent = 1;
                } else {
                    maxPercent = 0.5;
                }
                if (pos == Const.ARMOR) {
                    return getIntValue(Math.floor(getStdLife(equipLevel) * 0.105 * maxPercent), name);
                } else {
                    return getIntValue(Math.floor(getStdLife(equipLevel) * 0.06 * maxPercent), name);
                }
            }
            case "speed":
                return getIntValue((int) Math.floor(equipLevel * 2 * 0.15), name);
            case "str":
            case "con":
            case "wiz":
            case "dex":
                return (int) Math.floor(equipLevel * 0.1);
            case "all_attrib":
                return (int) Math.floor(equipLevel * 0.05);
            default:
                return 0;
        }
    }

    /**
     * 取属性的标称值
     */
    public static int getAttribStdValueByName(int equipLevel, int pos, String name) {
        switch (name) {
            case "power":
                return getIntValue(Math.floor(getStdLife(equipLevel) * 0.4 * 0.4 * 0.3), name);
            case "def": {
                if (pos == Const.ARMOR) {
                    return getIntValue(Math.floor(getStdLife(equipLevel) / 15 * 0.5 * 0.55), name);
                } else {
                    return getIntValue(Math.floor(getStdLife(equipLevel) / 15 * 0.25 * 0.55), name);
                }
            }
            case "max_life": {

                if (pos == Const.ARMOR) {
                    return getIntValue(Math.floor(getStdLife(equipLevel) * 0.105 * 0.5), name);
                } else {
                    return getIntValue(Math.floor(getStdLife(equipLevel) * 0.06 * 0.5), name);
                }
            }
            case "max_mana": {
                if (pos == Const.ARMOR) {
                    return getIntValue(Math.floor(getStdLife(equipLevel) * 0.105 * 0.7), name);
                } else {
                    return getIntValue(Math.floor(getStdLife(equipLevel) * 0.06 * 0.7), name);
                }
            }
            case "speed":
                return getIntValue((int) Math.floor(equipLevel * 2 * 0.15), name);
            case "str":
            case "con":
            case "wiz":
            case "dex":
                return (int) Math.floor(equipLevel * 0.15);
            case "all_attrib":
                return (int) Math.floor(equipLevel * 0.1);
            default:
                return 0;
        }
    }
    /**
     * 取属性的最大值
     */
    public static int getAttribMaxValueByName(int equipLevel, int pos, String name) {
        switch (name) {
            case "power":
                return getIntValue(Math.floor(getStdLife(equipLevel) * 0.4 * 0.4 * 0.7), name);
            case "def": {
                double maxPercent = 0;
                if (equipLevel >= 100) {
                    maxPercent = 1.2;
                } else {
                    maxPercent = 0.95;
                }
                if (pos == Const.ARMOR) {
                    return getIntValue(Math.floor(getStdLife(equipLevel) / 15 * 0.5 * maxPercent), name);
                } else {
                    return getIntValue(Math.floor(getStdLife(equipLevel) / 15 * 0.25 * maxPercent), name);
                }
            }
            case "max_life": {
                double maxPercent = 0;// 最大值系数

                if (equipLevel >= 100) {
                    maxPercent = 1.05;
                } else {
                    maxPercent = 0.85;
                }
                if (pos == Const.ARMOR) {
                    return getIntValue(Math.floor(getStdLife(equipLevel) * 0.105 * maxPercent), name);
                } else {
                    return getIntValue(Math.floor(getStdLife(equipLevel) * 0.06 * maxPercent), name);
                }
            }
            case "max_mana": {
                double maxPercent = 0;//最大值系数

                if (equipLevel >= 100) {
                    maxPercent = 5;
                } else {
                    maxPercent = 2.1;
                }
                if (pos == Const.ARMOR) {
                    return getIntValue(Math.floor(getStdMana(equipLevel) * 0.105 * maxPercent), name);
                } else {
                    return getIntValue(Math.floor(getStdMana(equipLevel) * 0.06 * maxPercent), name);
                }
            }
            case "speed":
                return getIntValue((int) Math.floor(equipLevel * 2 * 0.67), name);
            case "str":
            case "con":
            case "wiz":
            case "dex":
                return (int) Math.floor(equipLevel * 0.25);
            case "all_attrib":
                return (int) Math.floor(equipLevel * 0.2);
            default:
                return 0;
        }
    }

}
